package com.itheima;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @ProjectName: ybxy6
 * @Titile: TreeSet
 * @Author: 鲁伍加
 * @Description: TODO
 */
public class TreeSetDemo {
    public static void main(String[] args) {
        int result = sum(1,2,3,4,5);
        System.out.println(result);
    }

    private static void test0() {
        //集合只能存贮引用数据类型
        TreeSet<Integer> set1 = new TreeSet<>();
        //1.包装成integer对象 ---自动装箱
        set1.add(5);
        set1.add(3);
        set1.add(4);
        set1.add(2);
        set1.add(1);
        for (Integer integer : set1) {
            System.out.println(integer);
        }
    }

    public static void test1() {
        TreeSet<Student> set = new TreeSet<>();
        set.add(new Student("小王", 18));
        set.add(new Student("小李", 19));
        set.add(new Student("小张", 20));
        set.add(new Student("小赵", 17));
        for (Student student : set) {
            System.out.println(student.getName() + "---" + student.getAge());
        }
    }

    public static void test2() {

        Comparator<Student> comparator = (o1, o2) -> o1.getAge() - o2.getAge();
        TreeSet<Student> set = new TreeSet<>(comparator);
        set.add(new Student("小王", 23));
        set.add(new Student("小李", 21));
        set.add(new Student("小张", 19));
        set.add(new Student("小赵", 20));
        for (Student student : set) {
            System.out.println(student.getName() + "---" + student.getAge());
        }
    }

    public static int sum(int... a) {
        int total = 0;
        for (int i = 0; i < a.length; i++) {
            total += a[i];
        }
        return total;
    }
}
